define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'events/mailsys/index',
                    add_url: 'events/mailsys/add',
                    edit_url: 'events/mailsys/edit',
                    del_url: 'events/mailsys/del',
                    multi_url: 'events/mailsys/multi',
                    table: 'v_mailsys',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime,operate: false},
                        {field: 'userid', title: __('Userid')},
                        {field: 'mailtitle', title: __('Mailtitle'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                        {field: 'abstract', title: __('Abstract'), operate: false},
                        {field: 'mailcontent', title: __('Mailcontent'), operate: false},
                        {field: 'giftcode', title: __('Giftcode')},
                        {field: 'roomcard', title: __('Roomcard')},
                        {field: 'starttime', title: __('Starttime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange'},
                        {field: 'endtime', title: __('Endtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange'},
                        {field: 'Remarks', title: __('Remarks'), operate: false},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {'notstart': __('notstart'), 'osend': __('osend'), 'expired': __('expired')}},
                    ]
                ],
                search: false,
                //启用普通表单搜索
                commonSearch: true,
                //可以控制是否默认显示搜索单表,false则隐藏,默认为false
                searchFormVisible: false
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});